import { createClient } from 'redis';
import 'dotenv/config';
const config = {
  host: process.env.REDIS_HOST,
  port: process.env.REDIS_PORT,
  password: process.env.REDIS_PASSWORD,
};
const redis_url =
  'redis://' +
  (config.password ? `default:${config.password}@` : '') +
  `${config.host}:${config.port}`;
const client = createClient({ url: redis_url });
client.connect();

export const setCache = async (key, value, outTime = 86399) => {
  await client.set(key, value);
  await client.expire(key, outTime);
  return true;
};

export const getCache = async (key) => {
  const res = await client.GET(key);
  return res;
};
